<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: allen.qiang
// +----------------------------------------------------------------------

/**
 * 官网活动ajax类
 * @package  ajax
 * @subpackage  shop
 * @author   allen.qiang <allen.qiang@fistforward.com>
 */

quanli_require('module/base/customer/quanliCust.class.php');
quanli_require('module/base/activity/activitySpike.class.php');
quanli_require('module/base/shop/shopCart.class.php');

quanli_require('module/base/activity/activityConfig.class.php');

//add by 20141108 allen.qiang FUN-AC-0015 1元饼干订购活动 ---start
quanli_require('module/base/activity/Yuan1.class.php');
//add by 20141108 allen.qiang FUN-AC-0015 1元饼干订购活动 ---end

quanli_require('module/base/activity/Yuan9.class.php');
//add by 20141121 allen.qiang  FUN-AC-0020-BD建设银行五折购 ---start
quanli_require('module/base/activity/activityCbc.class.php');
//add by 20141121 allen.qiang  FUN-AC-0020-BD建设银行五折购 ---end
//add by 20141219 allen.qiang  FUN-AC-0021-浦发银行五折购 ---start
quanli_require('module/base/activity/activityPf.class.php');
//add by 20141219 allen.qiang  FUN-AC-0021-浦发银行五折购 ---end

class ajax_activity {

    public function execute() {

        if (isset($_REQUEST['operFlg']) && quanli_is_int($_REQUEST['operFlg'])) {

            switch($_REQUEST['operFlg']) {

                case 1: //预约秒杀
                    $this->appointment();
                    break;
                case 2: //立即秒杀
                    $this->spike();
                    break;
                case 3: //购买商品
                    $this->nowBuy();
                    break;
                case 4: //提交订单日志
                    $this->logActivity();
                    break;
                case 5: //订单成功录入订单号
                    $this->activitySpike();
                    break;
                case 6: //万圣节预约
                    $this->wsjSpike();
                    break;
                 case 7: //万圣节秒杀
                     $this->wsj_Spike();
                     break;
                case 8: //判断农业银行信用卡五折购的活动时间 allen.qiang 20141029 add
                    $this->nh_xyk();
                    break;
                case 9: //记录页面上【申请农行信用卡】按钮的点击次数 allen.qiang 20141029 add
                    $this->nh_xyk_log();
                    break;
                case 10: //判断会员是否有购买“1元饼干”的权限
                    $this->isCompetence();
                    break;
                case 11: //发送手机验证码
                    $this->sendSms();
                    break;
                case 12: //注册会员
                    $this->register();
                    break;
                case 13: //提交订单
                    $this->bill_submit_yuan1();
                    break;
                case 14: //保存试吃申请表信息
                    $this->saveTasting();
                    break;
                case 15:
                    $this->isCompetence9();
                    break;
                case 16: //注册会员
                    $this->register9();
                    break;
                case 17: //提交9元订单
                    $this->bill_submit_yuan9();
                    break;
                case 18: //得到建行信用卡五折购活动信息 add by 20141121 allen.qiang  FUN-AC-0020-BD建设银行五折购
                    $this->activity_cbc();
                    break;
                case 19: //建行信用卡五折购信息收集 add by 20141121 allen.qiang  FUN-AC-0020-BD建设银行五折购
                    $this->activity_cbc_master();
                    break;
                case 20: //建行信用卡五折购提交订单成功更新信息收集表 add by 20141121 allen.qiang  FUN-AC-0020-BD建设银行五折购
                    $this->activity_cbc_bill_masert();
                    break;
                case 21: //得到浦发银行五折购活动信息 add by 20141219 allen.qiang  FUN-AC-0021-浦发银行五折购
                    $this->activity_pf();
                    break;
                case 22: //记录页面上【浦发银行卡申请】按钮的点击次数 add by 20141219 allen.qiang  FUN-AC-0021-浦发银行五折购
                    $this->pf_yhk_log();
                    break;
                case 23: //得到银行五折购活动信息 add by 20141229 allen.qiang  2014-12-29 FUN-AC-0033-BD农行五折购
                    $this->activity_bank();
                    break;
                case 24: //添加商品到购物车 add by 20141229 allen.qiang  2014-12-29 FUN-AC-0033-BD农行五折购
                    $this->activity_nowbuy();
                    break;
                case 25: //记录页面上【银行信用卡申请】按钮的点击次数 dd by 20141229 allen.qiang  2014-12-29 FUN-AC-0033-BD农行五折购
                    $this->bank_log();
                    break;
                case 26: //注册带来源标记的会员
                    $this->publicRegister();
                    break;
                case 27: //提交苏州1元mini订单
                    $this->bill_submit_suzhou();
                    break;
                case 28: //提交情人节情书 add by allen.qiang 2015-01-27 FUN-AC-0038-BD情人节活动
                    $this->love_letter();
                    break;
                case 29: //根据秘钥显示情书 add by allen.qiang 2015-01-27 FUN-AC-0038-BD情人节活动
                    $this->love_letter_show();
                    break;
                case 30: //下单成功修改活动状态 add by allen.qiang 2015-01-28 FUN-AC-0038-BD情人节活动
                    $this->update_status();
                    break;
                case 31: //新年新老用户领取红包 add by allen.qiang 2015-02-12 FUN-AC-0042-新年送红包活动
                    $this->red_Envelopes();
                    break;
                case 32: //wap端注册带来源标记的会员 MK-FUN-AC-45-WAP端迷你拿破仑活动
                    $this->register_wap();
                    break;
                case 33: //提交WAP端拿破仑Mini蛋糕订单 MK-FUN-AC-45-WAP端迷你拿破仑活动
                    $this->bill_submit_wap();
                    break;
                case 34: //判断是否购买拿破仑mini蛋糕 MK-FUN-AC-MK-AC-1002-BD拿破仑Mini
                    $this->isMini();
                    break;
                case 35: //调查问卷信息收集 MK_AC-1004-儿童节问卷调查
                    $this->Questionnaire();
                    break;
                case 36: //MK-AC-1010-Mcake会员大调查
                    $this->member_survey();
                    break;
                case 37: //根据城市ID获取地区
                    $this->getCountyList();
                    break;
                case 38: //提交WAP端拿破仑Mini蛋糕订单
                    $this->submitMiniBill();
                    break;
                case 39: //查询活动商品剩余库存
                    $this->getActivityGoodsStock();
                    break;
                case 40: //记录图片点击
                    $this->clickLog();
                    break;
                case 999://获取提示信息
                    $this->rolling_tips();
                    break;
                default:
                    returnJsonData('参数错误');
                    break;


            }

        } else {
            returnJsonData('参数错误');
        }

    }

    private function rolling_tips()
    {
        global $G_SHOP;

        //---------------------读取提示配置----------------------
        quanli_require('module/base/activity/activityBank.class.php');
        $activity_config = new activityConfig($_REQUEST['config_code']);
        $config_array = $activity_config->config;
        $curTime = $G_SHOP->sys_datetime;
        $startTime =  date('Y-m-d H:i:s', strtotime($config_array['startTime']));
        $endTime = date('Y-m-d H:i:s', strtotime($config_array['endTime']));

        if($curTime>=$startTime && $curTime<=$endTime)
        {
            returnJsonData($config_array['content'],200);
        }
        returnJsonData('',404);

        //-------------------------------------------------------
    }

    //提交9.9元订单
    private function bill_submit_yuan9()
    {
        global $G_SHOP;
        $rs_array = array(
            'code'=>200,
            'message'=>'ok'
        );

        quanli_require('module/base/activity/activityConfig.class.php');

        $activity_config = new activityConfig('yuan9'); //活动配置
        $config_array = $activity_config->config;

        $yuan9 = new Yuan9();



        $send_time_array = $_REQUEST['send_time'];
        $send_time_start = mb_substr($send_time_array,3,5).':00';
        $send_time_end = mb_substr($send_time_array,9,5).':00';


        //error_log(print_r($send_time_start,1));
        if( empty( $_REQUEST['deliver_mobile'] ) )
        {
            returnJsonData('请填写收货人手机!');
        }

        if( empty( $_REQUEST['deliver_name'] ) )
        {
            returnJsonData('请填写收货人姓名!');
        }


        if($_REQUEST['country']==0)
        {
            returnJsonData('请选择收货地址的区信息!');
        }

        if( empty( $_REQUEST['deliver_address'] ) )
        {
            returnJsonData('请填写收货地址!');
        }

        //error_log(print_r($send_time_end,1));
        $bill = array();

        $bill['custID'] = $G_SHOP->currentCustomerID;

        $bill['country'] = $_REQUEST['country']; //区id
        $bill['deliver_name'] = $_REQUEST['deliver_name']; //收货人
        $bill['deliver_address'] = $_REQUEST['deliver_address'];//收货人地址
        $bill['deliver_mobile'] = $_REQUEST['deliver_mobile'];//收货人手机

        $bill['is_the_invoice'] = $_REQUEST['is_the_invoice'];
        $bill['invoice_title_type'] = $_REQUEST['invoice_title_type'];//1：个人 2：单位
        $bill['invoice_title'] = $_REQUEST['invoice_title']; //发票抬头

        //$bill['invoice_content'] = ''; //发票内容

        $bill['payTypeID'] = $_REQUEST['payTypeID']; //支付方式ID
        $bill['payment_method_id'] = 58; //付款方式


        $bill['send_date'] = $_REQUEST['send_date'];
        $bill['send_start_time'] = $send_time_start;
        $bill['send_end_time'] = $send_time_end;

        $bill['billPromotion'] = $config_array['billPromotion'];//促销渠道



        $result_array = $yuan9->create_bill($bill,$config_array);
        //error_log(print_r($result_array,1));
        $rs_array['code'] = $result_array['code'];
        $rs_array['message'] = $result_array['message'];
        if($result_array['code']==200)
        {
            $rs_array['bill_no'] = $result_array['bill_no'];
            returnJsonData($rs_array['bill_no'],$rs_array['code']);
        }


        returnJsonData($rs_array['message'],$rs_array['code']);
    }

    /**
     * 判断会员是否有购买“1元饼干”的权限
     * @author  20141107 allen.qiang <allen.qiang@fistforward.com>
     */
    public function isCompetence9(){
        global $G_SHOP;

        if (!$G_SHOP->currentCustomerID) {
            returnJsonData('会员未登录', 1);
        }


        //实例化"1元饼干"购买活动类
        $activity_yuan9 = new Yuan9();
        $_REQUEST['custID']=$G_SHOP->currentCustomerID;

        $result_array= $activity_yuan9->isCompetence($_REQUEST);
        returnJsonData($result_array['message'], $result_array['code']);
    }

    //提交1元订单
    private function bill_submit_yuan1()
    {
        global $G_SHOP;
        $rs_array = array(
            'code'=>200,
            'message'=>'ok'
        );

        quanli_require('module/base/activity/activityConfig.class.php');

        $activity_config = new activityConfig('yuan1'); //活动配置
        $config_array = $activity_config->config;

        $yuan1 = new Yuan1();



        $send_time_array = $_REQUEST['send_time'];
        $send_time_start = mb_substr($send_time_array,3,5).':00';
        $send_time_end = mb_substr($send_time_array,9,5).':00';


        //error_log(print_r($send_time_start,1));
        if( empty( $_REQUEST['deliver_mobile'] ) )
        {
            returnJsonData('请填写收货人手机!');
        }

        if( empty( $_REQUEST['deliver_name'] ) )
        {
            returnJsonData('请填写收货人姓名!');
        }


        if($_REQUEST['country']==0)
        {
            returnJsonData('请选择收货地址的区信息!');
        }

        if( empty( $_REQUEST['deliver_address'] ) )
        {
            returnJsonData('请填写收货地址!');
        }

        //error_log(print_r($send_time_end,1));
        $bill = array();

        $bill['custID'] = $G_SHOP->currentCustomerID;

        $bill['country'] = $_REQUEST['country']; //区id
        $bill['deliver_name'] = $_REQUEST['deliver_name']; //收货人
        $bill['deliver_address'] = $_REQUEST['deliver_address'];//收货人地址
        $bill['deliver_mobile'] = $_REQUEST['deliver_mobile'];//收货人手机

        $bill['is_the_invoice'] = $_REQUEST['is_the_invoice'];
        $bill['invoice_title_type'] = $_REQUEST['invoice_title_type'];//1：个人 2：单位
        $bill['invoice_title'] = $_REQUEST['invoice_title']; //发票抬头

        //$bill['invoice_content'] = ''; //发票内容

        $bill['payTypeID'] = $_REQUEST['payTypeID']; //支付方式ID
        $bill['payment_method_id'] = 58; //付款方式


        $bill['send_date'] = $_REQUEST['send_date'];
        $bill['send_start_time'] = $send_time_start;
        $bill['send_end_time'] = $send_time_end;

        $bill['billPromotion'] = $config_array['billPromotion'];//促销渠道



        $result_array = $yuan1->create_bill($bill,$config_array);
        //error_log(print_r($result_array,1));
        $rs_array['code'] = $result_array['code'];
        $rs_array['message'] = $result_array['message'];
        if($result_array['code']==200)
        {
            $rs_array['bill_no'] = $result_array['bill_no'];
            returnJsonData($rs_array['bill_no'],$rs_array['code']);
        }

        returnJsonData($rs_array['message'],$rs_array['code']);
    }


    //预约秒杀
    private function appointment()
    {
        global $G_SHOP;

        if (!$G_SHOP->currentPCustID) {
            returnJsonData('会员未登录', 1);
        }
        //实例化预约秒杀类
        $activitySpike=new activitySpike();

        $_REQUEST['creator'] = $G_SHOP->currentCustomerID;
        $_REQUEST['pcustID']=$G_SHOP->currentPCustID;
        $_REQUEST['appointmentTime']=date('Y-m-d H:i:s');
        $_REQUEST['isSpike']=0;
        if(date('Y-m-d H:i:s')>date('Y-m-d 16:00:00'))//预约时间控制
            $_REQUEST['spikeDate'] = date('Y-m-d',strtotime('+1 day'));
        else
            $_REQUEST['spikeDate'] = date('Y-m-d');

        //新增/修改
        $result_array = $activitySpike->saveSpike( $_REQUEST );
        returnJsonData($result_array['message'], $result_array['code']);
    }

    //立即秒杀
    private function spike()
    {
        global $G_SHOP;

        if (!$G_SHOP->currentPCustID) {
            returnJsonData('会员未登录', 1);
        }
        //实例化预约秒杀类
        $activitySpike=new activitySpike();

        $_REQUEST['pcustID']=$G_SHOP->currentPCustID;
        $_REQUEST['isSpike']=1;
        $_REQUEST['spikeDate'] = date('Y-m-d');
        $_REQUEST['spikeTime'] = date('Y-m-d H:i:s');

        //新增/修改
        $result_array = $activitySpike->saveSpike( $_REQUEST );
        returnJsonData($result_array['message'], $result_array['code']);
    }

    //立即购买
    public  function nowBuy() {

        if (!isset($_REQUEST['postID'], $_REQUEST['goods_amount']) || !quanli_is_int($_REQUEST['postID'])) {
            returnJsonData('参数错误');
        }

        if (!quanli_is_int($_REQUEST['goods_amount'])) {
            $_REQUEST['goods_amount'] = 1;
        }

        //实例购物车类
        $shopCart = new shopCart();


        //添加普通商品到购物车
        $result_array = $shopCart->nowBuy_activity($_REQUEST['postID'], $_REQUEST['goods_amount'],$_REQUEST['goods_type']);

        if ($result_array['code'] == 200) {
            returnJsonData($result_array['message'], $result_array['code'], $result_array['data']);
        } else {
            returnJsonData($result_array['message'], $result_array['code']);
        }
    }

    //提交订单日志
    public function logActivity(){
        global $G_SHOP;

        if (!$G_SHOP->currentPCustID) {
            returnJsonData('会员未登录', 1);
        }
        //实例化预约秒杀类
        $activitySpike=new activitySpike();

        $_REQUEST['creator'] = $G_SHOP->currentCustomerID;
        $_REQUEST['pcustID']=$G_SHOP->currentPCustID;

        //新增提交订单日志
        $result_array = $activitySpike->saveLog( $_REQUEST );
        returnJsonData($result_array['message'], $result_array['code']);
    }

    //订单成功录入订单号
    public function activitySpike(){
        global $G_SHOP;

        if (!$G_SHOP->currentPCustID) {
            returnJsonData('会员未登录', 1);
        }
        //实例化预约秒杀类
        $activitySpike=new activitySpike();

        $_REQUEST['pcustID']=$G_SHOP->currentPCustID;
        $_REQUEST['spikeDate'] = date('Y-m-d');
        //订单成功录入订单号
        $result_array = $activitySpike->upSpike( $_REQUEST );
        returnJsonData($result_array['message'], $result_array['code']);
    }

    //万圣节预约
    public function wsjSpike(){
        global $G_SHOP;

        if (!$G_SHOP->currentPCustID) {
            returnJsonData('会员未登录', 1);
        }
        //实例化预约秒杀类
        $activitySpike=new activitySpike();

        $_REQUEST['creator'] = $G_SHOP->currentCustomerID;
        $_REQUEST['pcustID']=$G_SHOP->currentPCustID;
        $_REQUEST['appointmentTime']=date('Y-m-d H:i:s');
        $_REQUEST['isSpike']=0;
        $_REQUEST['spikeDate'] = $activitySpike->getWeekSpikeDate(date("w"),1);

        //新增/修改
        $result_array = $activitySpike->saveWsjSpike( $_REQUEST );
        returnJsonData($result_array['message'], $result_array['code']);
    }

    //万圣节秒杀
    private function wsj_Spike()
    {
        global $G_SHOP;

        if (!$G_SHOP->currentPCustID) {
            returnJsonData('会员未登录', 1);
        }
        //实例化预约秒杀类
        $activitySpike=new activitySpike();

        //mod by allen.qiang  万圣节秒杀调整 start
        $_REQUEST['creator'] = $G_SHOP->currentCustomerID;
        $_REQUEST['appointmentTime']=date('Y-m-d H:i:s');
        //mod by allen.qiang  万圣节秒杀调整 end

        $_REQUEST['pcustID']=$G_SHOP->currentPCustID;
        $_REQUEST['isSpike']=1;
        $_REQUEST['spikeDate'] = date('Y-m-d');
        $_REQUEST['spikeTime'] = date('Y-m-d H:i:s');

        //新增/修改
        //mod by allen.qiang  万圣节秒杀调整 start
        //$result_array = $activitySpike->saveWsjSpike( $_REQUEST );
        $result_array = $activitySpike->WsjmsSpike( $_REQUEST );
        //mod by allen.qiang  万圣节秒杀调整 end
        returnJsonData($result_array['message'], $result_array['code']);
    }

    //判断农业银行信用卡五折购的活动时间 allen.qiang 20141029 add
    public function nh_xyk(){
        global $G_SHOP;

        if (!$G_SHOP->currentPCustID) {
            returnJsonData('会员未登录', 1);
        }
        //实例化活动类
        $activitySpike=new activitySpike();

        $result_array = $activitySpike->nh_xyk_isDate();
        $arry=array( 'code' => $result_array );
        returnJsonData("", $arry['code']);
    }

    //记录页面上【申请农行信用卡】按钮的点击次数 allen.qiang 20141029 add
    public function nh_xyk_log(){
        global $G_SHOP;

      /*  if (!$G_SHOP->currentPCustID) {
            returnJsonData('会员未登录', 1);
        }*/
        //实例化活动类
        $activitySpike=new activitySpike();

        $result_array = $activitySpike->nh_xyk_log();
        returnJsonData($result_array['message'], $result_array['code']);
    }

    /**
     * 判断会员是否有购买“1元饼干”的权限
     * @author  20141107 allen.qiang <allen.qiang@fistforward.com>
     */
    public function isCompetence(){
        global $G_SHOP;

        if (!$G_SHOP->currentCustomerID) {
            returnJsonData('会员未登录', 1);
        }

        //实例化"1元饼干"购买活动类
        $activity_yuan1 = new Yuan1();
        $_REQUEST['custID']=$G_SHOP->currentCustomerID;
        $result_array= $activity_yuan1->isCompetence($_REQUEST);
        returnJsonData($result_array['message'], $result_array['code']);
    }

    /**
     * 发送手机验证码
     *  @author  20141107 allen.qiang <allen.qiang@fistforward.com>
     */
    private function sendSms() {

        global $G_SHOP;

        //加载短信类
        quanli_include('module/base/common/quanliSms.class.php');

        //实例化短信类
        $quanliSms = new quanliSms();

        if (!isset($_REQUEST['mobile'], $_REQUEST['template']) || !is_mobile($_REQUEST['mobile']) || empty($_REQUEST['template'])) {
            returnJsonData('参数错误');
        }

        $mobile = $_REQUEST['mobile']; //手机号码
        $template = $_REQUEST['template']; //消息模板

        $current_time = time(); //当前时间戳
        $last_send_time = $G_SHOP->sessionCache_get('sms_yzm_time_' . $mobile); //上一次发放短信的时间戳
        if (!empty($last_send_time) && $current_time - $last_send_time < 60) {
            returnJsonData('手机短信已发送，请一分钟以后再试');
        }


        /**
         * ============================
         * 发送短信
         * ============================
         */

        //生成短信验证码
        $sms_yzm = $quanliSms->createSmsCode();

        //生成短信内容
        $data_array = array(
            '$sms_yzm' => $sms_yzm,
            '$mobile' => $mobile
        );
        $sms_content = $quanliSms->getSmsContent( $template, $data_array );
        if (!$sms_content) {
            returnJsonData('短信初始化失败', 404);
        }

        //发送短信
        $result_array = $quanliSms->sendSMS( $mobile, $sms_content );

        /**
         * ============================
         * 发送短信
         * ============================
         */

        if ($result_array['code'] == 200) {

            //保存短信验证码到redis
            $G_SHOP->sessionCache_set('sms_yzm_' . $mobile, md5($sms_yzm), 3600);//将验证码信息保存到memcache中去
            $G_SHOP->sessionCache_set('sms_yzm_time_' . $mobile, time(), 3600);

        }

        returnJsonData($result_array['message'], $result_array['code']);

    }


    /**
     * 注册会员信息
     *  @author  20141107 allen.qiang <allen.qiang@fistforward.com>
     */
    private function register9() {
        global $G_SHOP;

        //实例化"1元饼干"购买活动类
        $activity_yuan9 = new Yuan9();

        $result_array= $activity_yuan9->register();
        returnJsonData($result_array['message'], $result_array['code']);
    }

    /**
     * 注册会员信息
     *  @author  20141107 allen.qiang <allen.qiang@fistforward.com>
     */
    private function register() {
        global $G_SHOP;

        //实例化"1元饼干"购买活动类
        $activity_yuan1 = new Yuan1();

        $result_array= $activity_yuan1->register();
        returnJsonData($result_array['message'], $result_array['code']);
    }


    /**
     * 保存试吃申请表信息
     * @author  20141111 allen.qiang <allen.qiang@fistforward.com>
     */
    private function saveTasting() {
        global $G_SHOP;
        quanli_require('module/base/activity/activityTasting.class.php');

        //实例试吃活动类
        $activityTasting=new activityTasting();
        $_REQUEST["custID"]=$G_SHOP->currentCustomerID; //会员名
        $_REQUEST["pcustID"]=$G_SHOP->currentPCustID;//会员ID

        $result_array= $activityTasting->saveTasting($_REQUEST);
        returnJsonData($result_array['message'], $result_array['code']);
    }

    /**
     * 得到建行信用卡五折购活动信息
     * @author  20141120 allen.qiang <allen.qiang@fistforward.com> FUN-AC-0020-BD建设银行五折购
     */
    private function activity_cbc() {
        global $G_SHOP;

        //实例建设银行五折购活动类
        $activityCBC=new activityCbc();
        $_REQUEST["pcustID"]=$G_SHOP->currentPCustID;//会员ID
        $activity_master=$activityCBC->activity_master($_REQUEST);
        returnJsonData("ok", "200",$activity_master);
    }
    /**
     * 建行信用卡五折购信息收集
     * @author  20141120 allen.qiang <allen.qiang@fistforward.com> FUN-AC-0020-BD建设银行五折购
     */
    private function activity_cbc_master() {
        global $G_SHOP;

        $_REQUEST["custID"]=$G_SHOP->currentCustomerID; //会员名
        $_REQUEST["pcustID"]=$G_SHOP->currentPCustID;//会员ID
        //实例建设银行五折购活动类
        $activityCBC=new activityCbc();
        $activity_master=$activityCBC->activity_cbc($_REQUEST);
        returnJsonData($activity_master['message'], $activity_master['code']);
    }
    /**
     * 订单提交成功更新建行信用卡五折购信息收集表信息
     * @author  20141121 allen.qiang <allen.qiang@fistforward.com> FUN-AC-0020-BD建设银行五折购
     */
    private function activity_cbc_bill_masert() {
        global $G_SHOP;

        //实例建设银行五折购活动类
        $activityCBC=new activityCbc();
        $_REQUEST["custID"]=$G_SHOP->currentCustomerID; //会员名
        $_REQUEST["pcustID"]=$G_SHOP->currentPCustID;//会员ID

        $activity_master=$activityCBC->activity_cbc($_REQUEST);
        returnJsonData($activity_master['message'], $activity_master['code']);
    }
    /**
     * 得到浦发银行五折购活动信息
     * @author  20141119 allen.qiang <allen.qiang@fistforward.com> FUN-AC-0021-浦发银行五折购
     */
    private function activity_pf() {
        global $G_SHOP;
        //实例建设银行五折购活动类
        $activityPf=new activityPf();
        $_REQUEST["pcustID"]=$G_SHOP->currentPCustID;//会员ID
        $activity_master=$activityPf->activity_master($_REQUEST);
        returnJsonData("ok", "200",$activity_master);
    }

    /**
     * 记录页面上【浦发银行五折购】按钮的点击次数
     * @author  20141119 allen.qiang <allen.qiang@fistforward.com> FUN-AC-0021-浦发银行五折购
     */
    public function pf_yhk_log(){
        global $G_SHOP;

        //实例化活动类
        $activityPf=new activityPf();
        $result_array = $activityPf->pf_yhk_log("pf_yhk");
        returnJsonData($result_array['message'], $result_array['code']);
    }

    /**
     * 得到银行五折购活动信息
     * @author  20141229 allen.qiang <allen.qiang@fistforward.com>
     */
    private function activity_bank() {
        quanli_require('module/base/activity/activityBank.class.php');
        global $G_SHOP;
        //实例银行五折购活动类
        $activityBank=new activityBank();
        $_REQUEST["pcustID"]=$G_SHOP->currentPCustID;//会员ID
        $activity_master=$activityBank->activity_master($_REQUEST,$_REQUEST["bankName"]);
        returnJsonData("ok", "200",$activity_master);
    }

    /**
     * 添加活动商品到购物车
     * $_REQUEST['postID'] 商品网购ID
     * $_REQUEST['goods_amount'] 商品数量
     * $_REQUEST['nowbuyName'] 购物车名称
     * $_REQUEST['activityName'] 活动配置名称
     * @author  20141229 allen.qiang <allen.qiang@fistforward.com>
     */
    public  function activity_nowbuy() {

        if (!isset($_REQUEST['postID'], $_REQUEST['goods_amount']) || !quanli_is_int($_REQUEST['postID'])) {
            returnJsonData('参数错误');
        }

        if (!quanli_is_int($_REQUEST['goods_amount'])) {
            $_REQUEST['goods_amount'] = 1;
        }

        //实例购物车类
        $shopCart = new shopCart();

        //添加普通商品到购物车
        $result_array = $shopCart->activity_nowBuy($_REQUEST['postID'], $_REQUEST['goods_amount'],$_REQUEST['nowbuyName'],$_REQUEST["activityName"]);

        if ($result_array['code'] == 200) {
            returnJsonData($result_array['message'], $result_array['code'], $result_array['data']);
        } else {
            returnJsonData($result_array['message'], $result_array['code']);
        }
    }
    /**
     * 记录页面上【申请银行信用卡】按钮的点击次数
     * @author  20141229 allen.qiang <allen.qiang@fistforward.com>
     */
    public function bank_log(){
        quanli_require('module/base/activity/activityBank.class.php');

        //实例银行五折购活动类
        $activityBank=new activityBank();
        $result_array = $activityBank->bank_log($_REQUEST['bank_code']);
        returnJsonData($result_array['message'], $result_array['code']);
    }

    /**
     * 注册带来源标记的会员信息
     *  @author  20150108 allen.qiang <allen.qiang@fistforward.com>
     */
    private function publicRegister() {
        quanli_require('module/base/activity/activityBank.class.php');
        //实例化活动类
        $activity_config = new activityConfig($_REQUEST["config_code"]); //活动配置
        $config_array = $activity_config->config;
        $_REQUEST['cust_source_mark']=$config_array["cust_source_mark"];
        $activityBank=new activityBank();
        $result_array= $activityBank->register();
        returnJsonData($result_array['message'], $result_array['code']);
    }

    //提交苏州一元mini订单
    private function bill_submit_suzhou()
    {
        global $G_SHOP;
        $rs_array = array(
            'code'=>200,
            'message'=>'ok'
        );

        quanli_require('module/base/activity/activityConfig.class.php');
        quanli_require('module/base/activity/activityYuan1.class.php');

        $activity_config = new activityConfig("activity_suzhou_yuan1"); //活动配置
        $config_array = $activity_config->config;


        $send_time_array = $_REQUEST['send_time'];
        $send_time_start = mb_substr($send_time_array,3,5).':00';
        $send_time_end = mb_substr($send_time_array,9,5).':00';


        //error_log(print_r($send_time_start,1));
        if( empty( $_REQUEST['deliver_mobile'] ) )
        {
            returnJsonData('请填写收货人手机!');
        }

        if( empty( $_REQUEST['deliver_name'] ) )
        {
            returnJsonData('请填写收货人姓名!');
        }


        if($_REQUEST['country']==0)
        {
            returnJsonData('请选择收货地址的区信息!');
        }

        if( empty( $_REQUEST['deliver_address'] ) )
        {
            returnJsonData('请填写收货地址!');
        }

        //error_log(print_r($send_time_end,1));
        $bill = array();

        $bill['custID'] = $G_SHOP->currentCustomerID;

        $bill['country'] = $_REQUEST['country']; //区id
        $bill['deliver_name'] = $_REQUEST['deliver_name']; //收货人
        $bill['deliver_address'] = $_REQUEST['deliver_address'];//收货人地址
        $bill['deliver_mobile'] = $_REQUEST['deliver_mobile'];//收货人手机

        $bill['is_the_invoice'] = $_REQUEST['is_the_invoice'];
        $bill['invoice_title_type'] = $_REQUEST['invoice_title_type'];//1：个人 2：单位
        $bill['invoice_title'] = $_REQUEST['invoice_title']; //发票抬头

        //$bill['invoice_content'] = ''; //发票内容

        $bill['payTypeID'] = $_REQUEST['payTypeID']; //支付方式ID
        $bill['payment_method_id'] = 58; //付款方式


        $bill['send_date'] = $_REQUEST['send_date'];
        $bill['send_start_time'] = $send_time_start;
        $bill['send_end_time'] = $send_time_end;

        $bill['billPromotion'] = $config_array['billPromotion'];//促销渠道


        $activityYuan1 = new activityYuan1();
        $result_array = $activityYuan1->create_bill($bill,$config_array);
        //error_log(print_r($result_array,1));
        $rs_array['code'] = $result_array['code'];
        $rs_array['message'] = $result_array['message'];
        if($result_array['code']==200)
        {
            $rs_array['bill_no'] = $result_array['bill_no'];
            returnJsonData($rs_array['bill_no'],$rs_array['code']);
        }


        returnJsonData($rs_array['message'],$rs_array['code']);
    }

    //保存情书信息
    public function love_letter(){
        quanli_require('module/base/activity/activityValentine.class.php');

        $activity_Valentine = new activityValentine(); //情人节活动信息类
        $activityValentine=$activity_Valentine->activity_love_letter($_REQUEST);
        returnJsonData($activityValentine['message'],$activityValentine['code']);
    }

    //根据秘钥显示情书信息
    public function love_letter_show(){
        quanli_require('module/base/activity/activityValentine.class.php');

        $activity_Valentine = new activityValentine(); //情人节活动信息类
        $activityValentine=$activity_Valentine->activity_love_letter_show($_REQUEST);
        returnJsonData($activityValentine['message'],$activityValentine['code'],$activityValentine['data']);
    }

    //下单成功修改活动状态
    public function update_status(){
        quanli_require('module/base/activity/activityValentine.class.php');

        $activity_Valentine = new activityValentine(); //情人节活动信息类
        $activityValentine=$activity_Valentine->update_status($_REQUEST);
        returnJsonData($activityValentine['message'],$activityValentine['code'],$activityValentine['data']);
    }

    //新年新老用户领取红包
    public function red_Envelopes(){
        quanli_require('module/base/activity/activityRedEnvelopes.class.php');

        //实例化新年红包活动类
        $activityRedEnvelopes = new activityRedEnvelopes();
        $config_array = $activityRedEnvelopes->activity_red_envelopes();

        returnJsonData($config_array['message'],$config_array['code']);
    }

    /**
     * wap端注册带来源标记的会员信息
     *  @author  2015-03-04 allen.qiang <allen.qiang@fistforward.com>
     */
    private function register_wap() {
        quanli_require('module/base/activity/activityWapMini.class.php');
        //实例化活动类
        $activity_config = new activityConfig($_REQUEST["config_code"]); //活动配置
        $config_array = $activity_config->config;
        $_REQUEST['cust_source_mark']=$config_array["cust_source_mark"];
        $activityWapMini=new activityWapMini();
        $result_array= $activityWapMini->quickLogin();
        returnJsonData($result_array['message'], $result_array['code']);
    }

    /**
     * wap端提交9.9元拿破仑mini订单
     *  @author  2015-03-04 allen.qiang <allen.qiang@fistforward.com>
     */
    private function bill_submit_wap()
    {
        global $G_SHOP;
        $rs_array = array(
            'code'=>200,
            'message'=>'ok'
        );

        quanli_require('module/base/activity/activityConfig.class.php');
        quanli_require('module/base/activity/activityWapMini.class.php');

        $activity_config = new activityConfig($_REQUEST["config_code"]); //活动配置
        $config_array = $activity_config->config;
        $config_array["config_code"]=$_REQUEST["config_code"];

        $send_time_array = $_REQUEST['send_time'];
        $send_time_start = mb_substr($send_time_array,3,5).':00';
        $send_time_end = mb_substr($send_time_array,9,5).':00';

        if( empty( $_REQUEST['deliver_mobile'] ) )
        {
            returnJsonData('请填写收货人手机!');
        }

        if( empty( $_REQUEST['deliver_name'] ) )
        {
            returnJsonData('请填写收货人姓名!');
        }


        if($_REQUEST['country']==0)
        {
            returnJsonData('请选择收货地址的区信息!');
        }

        if( empty( $_REQUEST['deliver_address'] ) )
        {
            returnJsonData('请填写详细地址!');
        }

        $bill = array();

        $bill['custID'] = $G_SHOP->currentCustomerID;

        $bill['country'] = $_REQUEST['country']; //区id
        $bill['deliver_name'] = $_REQUEST['deliver_name']; //收货人
        $bill['deliver_address'] = $_REQUEST['deliver_address'];//收货人地址
        $bill['deliver_mobile'] = $_REQUEST['deliver_mobile'];//收货人手机

        $bill['is_the_invoice'] = $_REQUEST['is_the_invoice'];
        $bill['invoice_title_type'] = $_REQUEST['invoice_title_type'];//1：个人 2：单位
        $bill['invoice_title'] = $_REQUEST['invoice_title']; //发票抬头
        $bill['invoice_amount'] =$_REQUEST['invoice_amount']; //发票金额

        $bill['payTypeID'] = $_REQUEST['payTypeID']; //支付方式ID
        $bill['payment_method_id'] = 58; //付款方式


        $bill['send_date'] = $_REQUEST['send_date'];
        $bill['send_start_time'] = $send_time_start;
        $bill['send_end_time'] = $send_time_end;

        $bill['billPromotion'] = $config_array['billPromotion'];//促销渠道


        //省份ID
        if(isset($_REQUEST['deliver_provinceid']) && !empty($_REQUEST['deliver_provinceid'])){
            $bill['deliver_provinceid'] = intval($_REQUEST['deliver_provinceid']);
        }

        //城市ID
        if(isset($_REQUEST['deliver_cityid']) && !empty($_REQUEST['deliver_cityid'])){
            $bill['deliver_cityid'] = intval($_REQUEST['deliver_cityid']);
        }

        $activityWapMini = new activityWapMini();
        $result_array = $activityWapMini->create_bill($bill,$config_array);

        $rs_array['code'] = $result_array['code'];
        $rs_array['message'] = $result_array['message'];
        if($result_array['code']==200)
        {
            $rs_array['bill_no'] = $result_array['bill_no'];
            returnJsonData($rs_array['bill_no'],$rs_array['code']);
        }

        returnJsonData($rs_array['message'],$rs_array['code']);
    }
    /**
     * wap端提交拿破仑mini订单
     *  @author  2015-04-24 allen.qiang
     */
    private function submitMiniBill()
    {
        global $G_SHOP;
        $rs_array = array(
            'code'=>200,
            'message'=>'ok'
        );

        quanli_require('module/base/activity/activityConfig.class.php');
        quanli_require('module/base/activity/activityWapMiniMultiCity.class.php');

        $activity_config = new activityConfig($_REQUEST["config_code"]); //活动配置
        $config_array = $activity_config->config;
        $config_array["config_code"]=$_REQUEST["config_code"];

        $send_time_array = $_REQUEST['send_time'];
        $send_time_start = mb_substr($send_time_array,3,5).':00';
        $send_time_end = mb_substr($send_time_array,9,5).':00';

        if( empty( $_REQUEST['deliver_mobile'] ) )
        {
            returnJsonData('请填写收货人手机!');
        }

        if( empty( $_REQUEST['deliver_name'] ) )
        {
            returnJsonData('请填写收货人姓名!');
        }


        if($_REQUEST['country']==0)
        {
            returnJsonData('请选择收货地址的区信息!');
        }

        if( empty( $_REQUEST['deliver_address'] ) )
        {
            returnJsonData('请填写详细地址!');
        }

        $bill = array();

        $bill['custID'] = $G_SHOP->currentCustomerID;

        $bill['country'] = $_REQUEST['country']; //区id
        $bill['deliver_name'] = $_REQUEST['deliver_name']; //收货人
        $bill['deliver_address'] = $_REQUEST['deliver_address'];//收货人地址
        $bill['deliver_mobile'] = $_REQUEST['deliver_mobile'];//收货人手机

        $bill['is_the_invoice'] = $_REQUEST['is_the_invoice'];
        $bill['invoice_title_type'] = $_REQUEST['invoice_title_type'];//1：个人 2：单位
        $bill['invoice_title'] = $_REQUEST['invoice_title']; //发票抬头
        $bill['invoice_amount'] =$_REQUEST['invoice_amount']; //发票金额

        $bill['payTypeID'] = $_REQUEST['payTypeID']; //支付方式ID
        $bill['payment_method_id'] = 58; //付款方式


        $bill['send_date'] = $_REQUEST['send_date'];
        $bill['send_start_time'] = $send_time_start;
        $bill['send_end_time'] = $send_time_end;

        $bill['billPromotion'] = $config_array['billPromotion'];//促销渠道


        //省份ID
        if(isset($_REQUEST['deliver_provinceid']) && !empty($_REQUEST['deliver_provinceid'])){
            $bill['deliver_provinceid'] = intval($_REQUEST['deliver_provinceid']);
        }

        //城市ID
        if(isset($_REQUEST['deliver_cityid']) && !empty($_REQUEST['deliver_cityid'])){
            $bill['deliver_cityid'] = intval($_REQUEST['deliver_cityid']);
        }

        $activityWapMini = new activityWapMiniMultiCity();
        $result_array = $activityWapMini->create_bill($bill,$config_array);

        $rs_array['code'] = $result_array['code'];
        $rs_array['message'] = $result_array['message'];
        if($result_array['code']==200)
        {
            $rs_array['bill_no'] = $result_array['bill_no'];
            returnJsonData($rs_array['bill_no'],$rs_array['code']);
        }

        returnJsonData($rs_array['message'],$rs_array['code']);
    }

    /**
     * 判断是否购买wap端拿破仑mini蛋糕
     *  @author  2015-03-10 allen.qiang <allen.qiang@fistforward.com>
     */
    private function isMini() {
        quanli_require('module/base/activity/activityWapMini.class.php');

        $arg_array = array(
            'custID' => $_REQUEST["custID"]
        );
        $activityWapMini=new activityWapMini();
        $result_array= $activityWapMini->isCompetenceBD($arg_array,$_REQUEST["config_code"]);
        returnJsonData($result_array['message'], $result_array['code']);
    }

    /**
     * 问卷调查信息收集 ---MK_AC-1004-儿童节问卷调查
     *  @author  2015-03-20 allen.qiang <allen.qiang@fistforward.com>
     */
    private function Questionnaire() {
        quanli_require('module/base/activity/activityQuestionnaire.class.php');

        $activityQuestionnaire=new activityQuestionnaire();
        $result_array= $activityQuestionnaire->get_activities_extend($_REQUEST["Mobile"],$_REQUEST["arg_array_list"]);
        returnJsonData($result_array['message'], $result_array['code']);
    }

    /**
     * MK-AC-1010-Mcake会员大调查
     *  @author  2015-04-16 allen.qiang@fistforward.com
     */
    private function member_survey() {

        quanli_require('module/base/activity/activityMemberSurvey.class.php');

        $activityMemberSurvey = new activityMemberSurvey();

        $result_array= $activityMemberSurvey->get_activities_extend($_REQUEST["mobile"],$_REQUEST["data"]);

        returnJsonData($result_array['message'], $result_array['code']);
    }

    public function getCountyList(){

        global $G_SHOP;

        $cityID = intval($_REQUEST['city_id']);

        $sysRegion = new sysRegion($G_SHOP->DBCA);

        $arg_array = array(
            'parentID' => $cityID,
            'region_level' =>3,
            'sortname' => 'sortOrder',
            'sortorder' => 'ASC'
        );

        $list = $sysRegion->getAreaManageList($arg_array);; //区信息

        if($list){
            returnJsonData('ok',200,$list);
        }else{
            returnJsonData('参数错误！',400);
        }

    }
    //查询活动商品剩余库存
    private function getActivityGoodsStock(){

        global $G_SHOP;

        if(!isset($_REQUEST['goods_code'],$_REQUEST['goods_num'],$_REQUEST['act_code']) || empty($_REQUEST['goods_code']) || empty($_REQUEST['goods_num'])|| empty($_REQUEST['act_code']) ){
            returnJsonData('缺少参数！',400);
        }

        $goods_code = trim($_REQUEST['goods_code']);
        $goods_num = intval($_REQUEST['goods_num']);
        $act_code = trim($_REQUEST['act_code']);

        $activityConfig = new activityConfig($act_code);

        $config_array = $activityConfig->config;

        $limitGoodsTotal = 0;

        //马卡龙配送总量上限 目前商品只有一个，多个限制总量的商品需要扩展limit_goods_total的值格式为：“商品编码1:数量1,商品编码2:数量2,......”
        $limitGoodsTotalArr = explode(',',$config_array['limit_goods_total']);



        if(count($limitGoodsTotalArr)==1){
            $limitGoodsTotalArray = explode(':',$config_array['limit_goods_total']);
            if($limitGoodsTotalArray[0] == $goods_code){
                $limitGoodsTotal += $limitGoodsTotalArray[1];
            }
        }else{
            foreach($limitGoodsTotalArr as $arr){
                if($arr[0] == $goods_code){
                    $limitGoodsTotal += $arr[1];
                    break;
                }
            }
        }

        //查询马卡龙售出数量
        $currSaleMacaronNumSql = "SELECT SUM(goods.goods_amount) AS num FROM bill_goods AS goods,bill_master AS bill".
            " WHERE goods.bill_no = bill.bill_no AND goods.product_code = '{$goods_code}' AND bill.bill_status <> 10 AND bill.createTime > '2015-04-30 10:00:00'";

        $currSaleMacaronNumRow = $G_SHOP->DBCA->stmt_query($currSaleMacaronNumSql);
        $currSaleMacaronNum = $currSaleMacaronNumRow[0]->num;

        $macaronSurplusNum = !is_null($currSaleMacaronNum)?intval($limitGoodsTotal-$currSaleMacaronNum):intval($limitGoodsTotal);

        $returnNum = ($macaronSurplusNum >= $goods_num) ? $goods_num : $macaronSurplusNum;

        unset($G_SHOP);

        returnJsonData('ok',200,$returnNum);
    }

    //记录图片点击次数
    public function clickLog(){

        global $G_SHOP;

        $city_id = $G_SHOP->get_cookie_info('EBSIG_CITY_ID');

        try {
            $G_SHOP->DBCA->beginTransaction();

            $activityLog = new entity('activity_log');
            $activityLog->creator = $G_SHOP->currentCustomerID==""?'NULL':$G_SHOP->currentCustomerID;
            $activityLog->pcustID = $city_id;
            $activityLog->sku = "icon";

            $G_SHOP->DBCA->save($activityLog) ;
            $G_SHOP->DBCA->commit();
            returnJsonData('ok',200);
        } catch (Exception $e) {

            $G_SHOP->DBCA->rollBack();
            if ($e->getCode() > 0)
                returnJsonData($e->getMessage(),$e->getCode());
            else {
                error_log($e->getMessage());
                returnJsonData('系统错误',400);
            }
        }
    }
}


